package 枚举与尺聚法;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class code77 {
    public static void main(String[] args) {

        List<List<Integer>> lists = combine(4, 2);
        lists.forEach(System.out::println);

    }


     static List<List<Integer>> combine(int n, int k) {
        List<List<Integer>> result = new ArrayList<>();
        dfs(1, n, k, new LinkedList<>(), result);
        return result;
    }

    static void dfs(int start, int n, int k, LinkedList<Integer> stack, List<List<Integer>> result) {
        if (stack.size() == k) {
            result.add(new ArrayList<>(stack));
            return;
        }

        for (int i = start; i <= n ; i++) {
            stack.push(i);
            dfs(i + 1, n, k, stack, result);
            stack.pop();
        }

    }

}
